export default defineEventHandler(async (event) => {
  // 模拟分类数据
  const categories: any[] = [
    {
      id: 1,
      name: '电子产品',
      slug: 'electronics',
      description: '各类电子设备和数码产品',
      icon: 'laptop',
      image: 'https://picsum.photos/400/300?random=20',
      parentId: null,
      level: 1,
      sort: 1,
      status: 'active',
      productCount: 45,
      children: [
        {
          id: 11,
          name: '笔记本电脑',
          slug: 'laptops',
          description: '便携式计算机设备',
          icon: 'laptop',
          image: 'https://picsum.photos/400/300?random=21',
          parentId: 1,
          level: 2,
          sort: 1,
          status: 'active',
          productCount: 12
        },
        {
          id: 12,
          name: '智能手机',
          slug: 'smartphones',
          description: '移动通信设备',
          icon: 'phone',
          image: 'https://picsum.photos/400/300?random=22',
          parentId: 1,
          level: 2,
          sort: 2,
          status: 'active',
          productCount: 18
        },
        {
          id: 13,
          name: '平板电脑',
          slug: 'tablets',
          description: '便携式平板设备',
          icon: 'tablet',
          image: 'https://picsum.photos/400/300?random=23',
          parentId: 1,
          level: 2,
          sort: 3,
          status: 'active',
          productCount: 8
        },
        {
          id: 14,
          name: '智能手表',
          slug: 'smartwatches',
          description: '可穿戴智能设备',
          icon: 'watch',
          image: 'https://picsum.photos/400/300?random=24',
          parentId: 1,
          level: 2,
          sort: 4,
          status: 'active',
          productCount: 7
        }
      ]
    },
    {
      id: 2,
      name: '电脑配件',
      slug: 'computer-accessories',
      description: '计算机周边设备和配件',
      icon: 'keyboard',
      image: 'https://picsum.photos/400/300?random=25',
      parentId: null,
      level: 1,
      sort: 2,
      status: 'active',
      productCount: 38,
      children: [
        {
          id: 21,
          name: '键盘鼠标',
          slug: 'keyboards-mice',
          description: '输入设备',
          icon: 'keyboard',
          image: 'https://picsum.photos/400/300?random=26',
          parentId: 2,
          level: 2,
          sort: 1,
          status: 'active',
          productCount: 15
        },
        {
          id: 22,
          name: '显示器',
          slug: 'monitors',
          description: '显示设备',
          icon: 'monitor',
          image: 'https://picsum.photos/400/300?random=27',
          parentId: 2,
          level: 2,
          sort: 2,
          status: 'active',
          productCount: 10
        },
        {
          id: 23,
          name: '存储设备',
          slug: 'storage',
          description: '数据存储设备',
          icon: 'hard-drive',
          image: 'https://picsum.photos/400/300?random=28',
          parentId: 2,
          level: 2,
          sort: 3,
          status: 'active',
          productCount: 8
        },
        {
          id: 24,
          name: '网络设备',
          slug: 'networking',
          description: '网络连接设备',
          icon: 'wifi',
          image: 'https://picsum.photos/400/300?random=29',
          parentId: 2,
          level: 2,
          sort: 4,
          status: 'active',
          productCount: 5
        }
      ]
    },
    {
      id: 3,
      name: '音频设备',
      slug: 'audio-equipment',
      description: '音频播放和录制设备',
      icon: 'headphones',
      image: 'https://picsum.photos/400/300?random=30',
      parentId: null,
      level: 1,
      sort: 3,
      status: 'active',
      productCount: 25,
      children: [
        {
          id: 31,
          name: '耳机',
          slug: 'headphones',
          description: '个人音频设备',
          icon: 'headphones',
          image: 'https://picsum.photos/400/300?random=31',
          parentId: 3,
          level: 2,
          sort: 1,
          status: 'active',
          productCount: 12
        },
        {
          id: 32,
          name: '音箱',
          slug: 'speakers',
          description: '音频播放设备',
          icon: 'speaker',
          image: 'https://picsum.photos/400/300?random=32',
          parentId: 3,
          level: 2,
          sort: 2,
          status: 'active',
          productCount: 8
        },
        {
          id: 33,
          name: '麦克风',
          slug: 'microphones',
          description: '音频录制设备',
          icon: 'mic',
          image: 'https://picsum.photos/400/300?random=33',
          parentId: 3,
          level: 2,
          sort: 3,
          status: 'active',
          productCount: 5
        }
      ]
    },
    {
      id: 4,
      name: '办公用品',
      slug: 'office-supplies',
      description: '办公设备和文具用品',
      icon: 'printer',
      image: 'https://picsum.photos/400/300?random=34',
      parentId: null,
      level: 1,
      sort: 4,
      status: 'active',
      productCount: 48,
      children: [
        {
          id: 41,
          name: '打印机',
          slug: 'printers',
          description: '文档打印设备',
          icon: 'printer',
          image: 'https://picsum.photos/400/300?random=35',
          parentId: 4,
          level: 2,
          sort: 1,
          status: 'active',
          productCount: 10
        },
        {
          id: 42,
          name: '文具用品',
          slug: 'stationery',
          description: '办公文具',
          icon: 'pen',
          image: 'https://picsum.photos/400/300?random=36',
          parentId: 4,
          level: 2,
          sort: 2,
          status: 'active',
          productCount: 25
        },
        {
          id: 43,
          name: '办公家具',
          slug: 'office-furniture',
          description: '办公桌椅等家具',
          icon: 'chair',
          image: 'https://picsum.photos/400/300?random=37',
          parentId: 4,
          level: 2,
          sort: 3,
          status: 'active',
          productCount: 13
        }
      ]
    }
  ]

  // 获取查询参数
  const query = getQuery(event)
  const level = parseInt(query.level as string)
  const parentId = parseInt(query.parentId as string)
  const status = query.status as string
  const includeChildren = query.includeChildren === 'true'

  // 过滤数据
  let filteredCategories = categories
  if (level) {
    filteredCategories = filteredCategories.filter(category => category.level === level)
  }
  if (parentId) {
    filteredCategories = filteredCategories.filter(category => category.parentId === parentId)
  }
  if (status) {
    filteredCategories = filteredCategories.filter(category => category.status === status)
  }

  // 如果不包含子分类，移除children字段
  if (!includeChildren) {
    filteredCategories = filteredCategories.map(category => {
      const { children, ...categoryWithoutChildren } = category
      return categoryWithoutChildren
    })
  }

  // 模拟延迟
  await new Promise(resolve => setTimeout(resolve, 200))

  return {
    code: 200,
    message: '获取分类列表成功',
    data: {
      categories: filteredCategories,
      total: filteredCategories.length
    }
  }
}) 